package com.bjpowernode.boss.mvc.controller;

import com.bjpowernode.boss.mvc.menus.MenuItem;
import com.bjpowernode.boss.mvc.menus.SubMenu;
import com.bjpowernode.boss.mvc.models.AjaxResult;
import com.bjpowernode.boss.mvc.models.dto.operator.LoginResponseDto;
import com.bjpowernode.boss.mvc.models.form.operator.LoginForm;
import com.bjpowernode.boss.mvc.service.OperatorService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/operator")
public class OperatorController {
    @Resource
    private OperatorService operatorService;

    @PostMapping("/login")
    public AjaxResult operatorLogin(@RequestBody @Validated LoginForm loginForm) {
        LoginResponseDto loginResponseDto = operatorService.operatorLogin(loginForm);
        return AjaxResult.ok(loginResponseDto);
    }

    @GetMapping("/menus")
    public AjaxResult getMenus(@RequestHeader("operatorId") Long operatorId){
        //调用service获取菜单
        List<SubMenu> subMenuList = operatorService.getMenusByLoginUser(operatorId);
        return  AjaxResult.ok(subMenuList);
    }
}
